package com.yuyang.gulimall.seckill.web;

import com.yuyang.common.utils.R;
import com.yuyang.gulimall.seckill.service.SeckillService;
import com.yuyang.gulimall.seckill.to.SecKillSkuRedisTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author yu yang
 * @date 2023/2/13 -18:55
 */
@Controller
public class SeckillWebController {
    @Autowired
    SeckillService seckillService;
    @ResponseBody
    @GetMapping("currentSeckillSkus")
    public R getCurrentSeckillSkus(){
        List<SecKillSkuRedisTo> vos =  seckillService.getCurrentSeckillSkus();
        return R.ok().setData(vos);
    }
    @GetMapping("/kill")
    public String kill(@RequestParam("killId")String killId, @RequestParam("key")String key, @RequestParam("num") Integer num, Model model){
        String orderSn = seckillService.kill(killId,key,num);
        model.addAttribute("orderSn",orderSn);
        return "success";
    }
}
